package com.singularity.onelabel.data;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by Lenovo on 2018/11/14.
 */

public class SharedPreferencesUtils {

    private static volatile SharedPreferencesUtils instance = null;
    private SharedPreferences.Editor editor = null;
    private SharedPreferences sharedPreferences = null;

    public static SharedPreferencesUtils getInstance(Context context){
        if (instance == null){
            synchronized (SharedPreferencesUtils.class){
                if (instance == null){
                    instance = new SharedPreferencesUtils();
                    instance.init(context);
                }
            }
        }
        return instance;
    }

    private void init(Context context){
        sharedPreferences = context.getSharedPreferences("sharedpreferences",Context.MODE_PRIVATE);
        editor = sharedPreferences.edit();
    }

    public void putBoolean(String key , boolean value){
        editor.putBoolean(key,value);
        editor.commit();
    }

    public boolean getBoolean(String key){

        return sharedPreferences.getBoolean(key,false);
    }
}
